package com.luojun.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.luojun.entity.Commodity;
import com.luojun.entity.Page;
import com.luojun.service.ACommodityService;

/**
 * Servlet implementation class ToCheckList
 */
@WebServlet("/ToCheckList")
public class ToCheckList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ToCheckList() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pageNum=request.getParameter("pageNum");
		int num=0;
		if(pageNum==null||pageNum.equals("")){
			num=1;
		}else{
			num=Integer.parseInt(pageNum);
		}
		ACommodityService acs = new ACommodityService();
		int count = acs.findCountByPage();
		Page<Commodity> p = new Page<Commodity>(num,20);
		p.setAllCount(count);
		List<Commodity> list = acs.findByPage(p.getNowPageNum(), p.getPageSize());
		p.setList(list);		
		request.setAttribute("page",p);
		request.getRequestDispatcher("WEB-INF/jsp/CommodityCheckList.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
